/*
 * Copyright (C) 2009 2DAI
 *
 * Este programa es Software Libre; usted puede redistribuirlo
 * y/o modificarlo bajo los términos de la "GNU General Public
 * License" como lo publica la "FSF Free Software Foundation",
 * o (a su elección) de cualquier versión posterior.
 *
 * Este programa es distribuido con la esperanza de que le será
 * útil, pero SIN NINGUNA GARANTIA; incluso sin la garantía
 * implícita por el MERCADEO o EJERCICIO DE ALGUN PROPOSITO en
 * particular. Vea la "GNU General Public License" para más
 * detalles.
 *
 * Usted debe haber recibido una copia de la "GNU General Public
 * License" junto con este programa, si no, escriba a la "FSF
 * Free Software Foundation, Inc.", 59 Temple Place - Suite 330,
 * Boston, MA  02111-1307, USA.
 */

/*
 * 
 * Autor : Marta Espejo
 */

package gui;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.StringTokenizer;
import javax.swing.DefaultComboBoxModel;
import on.Referees;

/**
 *
 * @author Alumno
 */
public class MaintReferee extends logic.ContentiPanel<Referees> {
    private int id;
    /** Creates new form MaintReferee */
    public MaintReferee() {
        initComponents();
        rellenarLiga();
    }

    /*metodo que retorna el contenido de los campos en un Jugador*/
    public Referees getContenido(){
        Referees r= new Referees();
        r.setId_Arbitros(id);
        r.setNombre(this.JTFnombre.getText());
        r.setApellidos(this.JTFapellido.getText());
        r.setDni(Integer.parseInt(this.JTFdni.getText()));
        r.setNacionalidad(this.JTFnacionalidad.getText());
        if (this.JFTFfechaNacimiento.getText().compareTo(" ") != 0) {
            Date fe = convertirFecha(this.JFTFfechaNacimiento.getText());
            System.out.println(fe);
            r.setFechaNacimiento(fe);
        }
        r.setDireccion(this.JTFdireccion.getText());
        r.setCodigoPostal(Integer.valueOf(this.JFTFcp.getText()));
        r.setProvincia(this.JTFprovincia.getText());
        r.setPoblacion(this.JTFpoblacion.getText());
        r.setTelefono(Integer.parseInt(this.JFTFtelefono.getText()));
        r.setEMail(this.JFTFcorreo.getText());
        r.setLiga(this.JCBliga.getItemAt(this.JCBliga.getSelectedIndex()).toString());
        r.setNumLicencia(Integer.parseInt(this.JFTFnumLicencia.getText()));
        return r;
    }

    /*mÃ©todo que pasa un String a tipo Date*/
    private Date convertirFecha(String text) {
        int dia,mes,ano;
        //separamos la cadena en tokens
        StringTokenizer token= new StringTokenizer(text, "-");
        dia=Integer.valueOf(token.nextToken());
        mes=Integer.valueOf(token.nextToken());
        ano=Integer.valueOf(token.nextToken());
        //creacion del GregorianCalendar para pasar a Date.
        GregorianCalendar g= new GregorianCalendar(ano,mes,dia);       
        return g.getTime();

    }

    public void setContenido(Referees r){
        this.id=r.getId_Arbitros();
        this.JFTFnumLicencia.setText(String.valueOf(r.getNumLicencia()));
        this.JTFnombre.setText(r.getNombre());
        this.JTFapellido.setText(r.getApellidos());
        this.JTFdni.setText(String.valueOf(r.getDni()));
        this.JTFnacionalidad.setText(r.getNacionalidad());
        this.JFTFfechaNacimiento.setText(reConvertirFecha(r.getFechaNacimiento()));
        this.JTFdireccion.setText(r.getDireccion());
        this.JFTFcp.setText(String.valueOf(r.getCodigoPostal()));
        this.JTFprovincia.setText(r.getProvincia());
        this.JTFpoblacion.setText(r.getPoblacion());
        this.JFTFtelefono.setText(String.valueOf(r.getTelefono()));
        this.JFTFcorreo.setText(r.getEMail());
        this.JCBliga.setSelectedItem(r.getLiga());
    }

     /**
     * mÃ©todo que convierte la fecha en formato dd-mm-yyyy
     * @param f
     * @return
     */
    private String reConvertirFecha(Date f ) {
        SimpleDateFormat año = new SimpleDateFormat("yyyy");
        SimpleDateFormat mes = new SimpleDateFormat("MM");
        SimpleDateFormat dia = new SimpleDateFormat("dd");
        String fecha=  dia.format(f)+"-"+ mes.format(f)+"-"+año.format(f);
       return fecha;
    }

     public void rellenarLiga (){
        Referees r= new Referees();
        JCBliga.setModel(new DefaultComboBoxModel(r.getArrayLiga()));
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        JTBdatos = new javax.swing.JTabbedPane();
        JPdatospersonales = new javax.swing.JPanel();
        JLnombre = new javax.swing.JLabel();
        JLdni = new javax.swing.JLabel();
        JLfechaNacimiento = new javax.swing.JLabel();
        JLdireccion = new javax.swing.JLabel();
        JLcp = new javax.swing.JLabel();
        JLprovincia = new javax.swing.JLabel();
        JLpoblacion2 = new javax.swing.JLabel();
        JTFdni = new javax.swing.JTextField();
        JFTFfechaNacimiento = new javax.swing.JFormattedTextField();
        JTFdireccion = new javax.swing.JTextField();
        JFTFcp = new javax.swing.JFormattedTextField();
        JTFprovincia = new javax.swing.JTextField();
        JFTFtelefono = new javax.swing.JFormattedTextField();
        JLprimerApellido = new javax.swing.JLabel();
        JTFapellido = new javax.swing.JTextField();
        JLnacionalidad = new javax.swing.JLabel();
        JTFnacionalidad = new javax.swing.JTextField();
        JLpoblacion = new javax.swing.JLabel();
        JTFpoblacion = new javax.swing.JTextField();
        JLpoblacion1 = new javax.swing.JLabel();
        JFTFcorreo = new javax.swing.JFormattedTextField();
        JTFnombre = new javax.swing.JTextField();
        JPdatosJugador = new javax.swing.JPanel();
        JLnumLicencia = new javax.swing.JLabel();
        JLliga = new javax.swing.JLabel();
        JFTFnumLicencia = new javax.swing.JFormattedTextField();
        JCBliga = new javax.swing.JComboBox();

        JLnombre.setText("Nombre");

        JLdni.setText("DNI");
        JLdni.setPreferredSize(new java.awt.Dimension(100, 14));

        JLfechaNacimiento.setText("Nacimiento");

        JLdireccion.setText("Dirección");

        JLcp.setText("CP");

        JLprovincia.setText("Provincia");

        JLpoblacion2.setText("Teléfono");

        JLprimerApellido.setText("Apellidos");

        JLnacionalidad.setText("Nacionalidad");

        JLpoblacion.setText("Población");

        JLpoblacion1.setText("Correo");

        javax.swing.GroupLayout JPdatospersonalesLayout = new javax.swing.GroupLayout(JPdatospersonales);
        JPdatospersonales.setLayout(JPdatospersonalesLayout);
        JPdatospersonalesLayout.setHorizontalGroup(
            JPdatospersonalesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(JPdatospersonalesLayout.createSequentialGroup()
                .addGap(76, 76, 76)
                .addGroup(JPdatospersonalesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(JPdatospersonalesLayout.createSequentialGroup()
                        .addComponent(JLnombre)
                        .addGap(18, 18, 18))
                    .addGroup(JPdatospersonalesLayout.createSequentialGroup()
                        .addGroup(JPdatospersonalesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(JLdireccion)
                            .addComponent(JLcp)
                            .addComponent(JLprovincia)
                            .addComponent(JLpoblacion2)
                            .addComponent(JLfechaNacimiento, javax.swing.GroupLayout.PREFERRED_SIZE, 68, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18))
                    .addGroup(JPdatospersonalesLayout.createSequentialGroup()
                        .addComponent(JLdni, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)))
                .addGroup(JPdatospersonalesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(JFTFcp, javax.swing.GroupLayout.PREFERRED_SIZE, 85, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(JPdatospersonalesLayout.createSequentialGroup()
                        .addGroup(JPdatospersonalesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(JFTFtelefono)
                            .addComponent(JTFprovincia, javax.swing.GroupLayout.DEFAULT_SIZE, 140, Short.MAX_VALUE))
                        .addGap(44, 44, 44)
                        .addGroup(JPdatospersonalesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(JPdatospersonalesLayout.createSequentialGroup()
                                .addGroup(JPdatospersonalesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(JLprimerApellido)
                                    .addComponent(JLnacionalidad))
                                .addGap(18, 18, 18)
                                .addGroup(JPdatospersonalesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(JPdatospersonalesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                        .addComponent(JTFnacionalidad, javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(JTFapellido, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 128, Short.MAX_VALUE))
                                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, JPdatospersonalesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                        .addComponent(JFTFcorreo, javax.swing.GroupLayout.Alignment.TRAILING)
                                        .addComponent(JTFpoblacion, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 124, Short.MAX_VALUE))))
                            .addGroup(JPdatospersonalesLayout.createSequentialGroup()
                                .addGap(18, 18, 18)
                                .addGroup(JPdatospersonalesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(JLpoblacion)
                                    .addComponent(JLpoblacion1)))))
                    .addComponent(JTFdireccion, javax.swing.GroupLayout.PREFERRED_SIZE, 342, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(JPdatospersonalesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addComponent(JFTFfechaNacimiento, javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(JTFdni, javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(JTFnombre, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 137, Short.MAX_VALUE)))
                .addContainerGap(64, Short.MAX_VALUE))
        );
        JPdatospersonalesLayout.setVerticalGroup(
            JPdatospersonalesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(JPdatospersonalesLayout.createSequentialGroup()
                .addGap(26, 26, 26)
                .addGroup(JPdatospersonalesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(JPdatospersonalesLayout.createSequentialGroup()
                        .addGroup(JPdatospersonalesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(JLnombre)
                            .addComponent(JTFnombre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(JPdatospersonalesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(JTFdni, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(JLdni, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(12, 12, 12)
                        .addGroup(JPdatospersonalesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(JLfechaNacimiento)
                            .addComponent(JFTFfechaNacimiento, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(12, 12, 12)
                        .addGroup(JPdatospersonalesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(JTFdireccion, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(JLdireccion))
                        .addGap(12, 12, 12)
                        .addGroup(JPdatospersonalesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(JFTFcp, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(JLcp))
                        .addGap(12, 12, 12)
                        .addGroup(JPdatospersonalesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(JTFprovincia, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(JLprovincia))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(JPdatospersonalesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(JFTFtelefono, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(JLpoblacion2, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(JPdatospersonalesLayout.createSequentialGroup()
                        .addGroup(JPdatospersonalesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(JTFapellido, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(JLprimerApellido))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(JPdatospersonalesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(JTFnacionalidad, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(JLnacionalidad))
                        .addGap(132, 132, 132)
                        .addGroup(JPdatospersonalesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(JTFpoblacion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(JLpoblacion))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(JPdatospersonalesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(JFTFcorreo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(JLpoblacion1, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap(26, Short.MAX_VALUE))
        );

        JTBdatos.addTab("Datos Personales", JPdatospersonales);

        JLnumLicencia.setText("Nº Licencia");

        JLliga.setText("Liga");

        JCBliga.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        javax.swing.GroupLayout JPdatosJugadorLayout = new javax.swing.GroupLayout(JPdatosJugador);
        JPdatosJugador.setLayout(JPdatosJugadorLayout);
        JPdatosJugadorLayout.setHorizontalGroup(
            JPdatosJugadorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(JPdatosJugadorLayout.createSequentialGroup()
                .addGap(61, 61, 61)
                .addGroup(JPdatosJugadorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(JLnumLicencia)
                    .addComponent(JLliga))
                .addGap(18, 18, 18)
                .addGroup(JPdatosJugadorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(JCBliga, javax.swing.GroupLayout.Alignment.LEADING, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(JFTFnumLicencia, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 147, Short.MAX_VALUE))
                .addContainerGap(341, Short.MAX_VALUE))
        );
        JPdatosJugadorLayout.setVerticalGroup(
            JPdatosJugadorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(JPdatosJugadorLayout.createSequentialGroup()
                .addGap(33, 33, 33)
                .addGroup(JPdatosJugadorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(JLnumLicencia)
                    .addComponent(JFTFnumLicencia, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(JPdatosJugadorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(JCBliga, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(JLliga))
                .addContainerGap(215, Short.MAX_VALUE))
        );

        JTBdatos.addTab("Datos Arbitro", JPdatosJugador);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(JTBdatos, javax.swing.GroupLayout.DEFAULT_SIZE, 629, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(JTBdatos, javax.swing.GroupLayout.DEFAULT_SIZE, 350, Short.MAX_VALUE)
        );
    }// </editor-fold>//GEN-END:initComponents


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JComboBox JCBliga;
    private javax.swing.JFormattedTextField JFTFcorreo;
    private javax.swing.JFormattedTextField JFTFcp;
    private javax.swing.JFormattedTextField JFTFfechaNacimiento;
    private javax.swing.JFormattedTextField JFTFnumLicencia;
    private javax.swing.JFormattedTextField JFTFtelefono;
    private javax.swing.JLabel JLcp;
    private javax.swing.JLabel JLdireccion;
    private javax.swing.JLabel JLdni;
    private javax.swing.JLabel JLfechaNacimiento;
    private javax.swing.JLabel JLliga;
    private javax.swing.JLabel JLnacionalidad;
    private javax.swing.JLabel JLnombre;
    private javax.swing.JLabel JLnumLicencia;
    private javax.swing.JLabel JLpoblacion;
    private javax.swing.JLabel JLpoblacion1;
    private javax.swing.JLabel JLpoblacion2;
    private javax.swing.JLabel JLprimerApellido;
    private javax.swing.JLabel JLprovincia;
    private javax.swing.JPanel JPdatosJugador;
    private javax.swing.JPanel JPdatospersonales;
    private javax.swing.JTabbedPane JTBdatos;
    private javax.swing.JTextField JTFapellido;
    private javax.swing.JTextField JTFdireccion;
    private javax.swing.JTextField JTFdni;
    private javax.swing.JTextField JTFnacionalidad;
    private javax.swing.JTextField JTFnombre;
    private javax.swing.JTextField JTFpoblacion;
    private javax.swing.JTextField JTFprovincia;
    // End of variables declaration//GEN-END:variables

    @Override
    public void enableTextFields(boolean boo) {
        this.JFTFnumLicencia.setEnabled(boo);
        this.JTFnombre.setEnabled(boo);
        this.JTFapellido.setEnabled(boo);
        this.JTFdni.setEnabled(boo);
        this.JTFnacionalidad.setEnabled(boo);
        this.JFTFfechaNacimiento.setEnabled(boo);
        this.JTFdireccion.setEnabled(boo);
        this.JFTFcp.setEnabled(boo);
        this.JTFprovincia.setEnabled(boo);
        this.JTFpoblacion.setEnabled(boo);
        this.JFTFtelefono.setEnabled(boo);
        this.JFTFcorreo.setEnabled(boo);
        this.JCBliga.setEnabled(boo);
    }

    @Override
    public void clearTextFields() {
        this.JFTFnumLicencia.setText("");
        this.JTFnombre.setText("");
        this.JTFapellido.setText("");
        this.JTFdni.setText("");
        this.JTFnacionalidad.setText("");
        this.JFTFfechaNacimiento.setText("");
        this.JTFdireccion.setText("");
        this.JFTFcp.setText("");
        this.JTFprovincia.setText("");
        this.JTFpoblacion.setText("");
        this.JFTFtelefono.setText("");
        this.JFTFcorreo.setText("");
    }

   

}
